package edu.berkeley.drivingbuddy;

import android.app.Activity;
import android.app.ExpandableListActivity;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.view.View;
import android.os.Bundle;
import android.content.Intent;

public class MyResults extends ExpandableListActivity {
	ExpandableListAdapter mAdapter;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.results);
		mAdapter = new ResultsListAdapter(this);
		setListAdapter(mAdapter);
		expandAll();
    }

    public void onResume(Bundle savedInstanceState) {
		expandAll();
	}

	private void expandAll() {
		for (int i  = 0; i < mAdapter.getGroupCount(); i++)
			getExpandableListView().expandGroup(i);
	}

	@Override
	public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
			long id) {
		int resultId = DrivingBuddy.getDatastore().getResultGroups().get(groupPosition).getResults().get(childPosition).getUniqueResultId();
		startActivity(new Intent(this,Result.class).putExtra("id", resultId)); 
		return true;
	}
	
	// called by inline call from the xml
	public void showMeHowItsDone(View v) {
		startActivity(new Intent(this,AboutScore.class)); 
	}


}
